﻿USE [TanNamChinh]
/*
Cập nhật CSDL ngày 02-01-2014
*/
--=============================================
--Thêm bảng quản lý Tạm ứng tài xế
CREATE TABLE [dbo].[tblAdvanceDriver](
	[ID_AdvanceDriver] [int] IDENTITY(1,1) NOT NULL,
	[AdvanceDate] [datetime] NULL,
	[ID_Driver] [int] NULL,
	[Amount] [float] NULL,
 CONSTRAINT [PK_tblAdvanceDriver] PRIMARY KEY CLUSTERED 
(
	[ID_AdvanceDriver] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblAdvanceDriver]  WITH CHECK ADD  CONSTRAINT [FK_tblAdvanceDriver_tblDriver] FOREIGN KEY([ID_Driver])
REFERENCES [dbo].[tblDriver] ([ID_Driver])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tblAdvanceDriver] CHECK CONSTRAINT [FK_tblAdvanceDriver_tblDriver]
GO

--=============================================
--Thêm quan hệ cascade delete tblCont và Unit cont
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblUnitCont_tblCont]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblUnitCont]'))
ALTER TABLE [dbo].[tblUnitCont] DROP CONSTRAINT [FK_tblUnitCont_tblCont]
GO
ALTER TABLE [dbo].[tblUnitCont]  WITH CHECK ADD  CONSTRAINT [FK_tblUnitCont_tblCont] FOREIGN KEY([ID_Cont])
REFERENCES [dbo].[tblCont] ([ID_Cont])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tblUnitCont] CHECK CONSTRAINT [FK_tblUnitCont_tblCont]
